﻿using System;
using System.Collections.Generic;
using Ext.Net;
using System.Xml;
using System.Xml.Xsl;
using ExaminationSys.DataAccess.Entity;
 

namespace ExaminationSys.SystemManage
{
    public partial class SystemUser : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                IList<sys_user> list = new List<sys_user>()
                                           {
                                               new sys_user {userid = "1232", username = "alex yu"},
                                               new sys_user {userid = "1232", username = "alex yu"},
                                               new sys_user {userid = "1232", username = "alex yu"},
                                               new sys_user {userid = "1232", username = "alex yu"},
                                               new sys_user {userid = "1232", username = "alex yu"}
                                           };
                this.Store1.DataSource = list;
                this.Store1.DataBind();
            }
        }
        //绑定Grid
        //protected void sys_user_DataBind(object sender, StoreRefreshDataEventArgs e)
        //{
        //    // sys_userMgr mgr = new sys_userMgr();
        //    e.Total = 12312;
        //    IList<sys_user> list = new List<sys_user>(){ new sys_user{ userid="1232",username="alex yu"},
        //       new sys_user{ userid="1232",username="alex yu"},
        //       new sys_user{ userid="1232",username="alex yu"},
        //       new sys_user{ userid="1232",username="alex yu"},
        //       new sys_user{ userid="1232",username="alex yu"}
        //   };
        //    sys_user_MainStore.DataSource = list;
        //    sys_user_MainStore.DataBind();
        //}
        //删除数据
        protected void BtnDel_Click(object sender, DirectEventArgs e)
        {
           // sys_userMgr mgr = new sys_userMgr();
            //RowSelectionModel sm = sys_user_Grid.SelectionModel.Primary as RowSelectionModel;
            //foreach (SelectedRow row in sm.SelectedRows)
            //{
            //    sys_user _sys_user = new sys_user();
            //    _sys_user.userid =  row.RecordID ;
            //    //if (mgr.Del_sys_user(_sys_user))
            //    //    X.Msg.Notify("成功", "<font color='green' size='4'>已经成功删除选中的记录</font>").Show();
            //    //else
            //    //    X.Msg.Notify("失败", "<font color='green' size='4'>删除记录失败，请您重试！</font>").Show();
            //}
            //sys_user_Grid.Reload();
        }
        protected void BtnSave_Click(object sender, DirectEventArgs e)
        {
            //sys_userMgr mgr = new sys_userMgr();
            sys_user _sys_user = new sys_user();
            if (Hid.Text.Length > 0)
               //_sys_user = mgr.FindById_sys_user(int.Parse(Hid.Text));
            
			_sys_user.usertypeid = Txtusertypeid.Text.Trim();
		 
			_sys_user.username = Txtusername.Text.Trim();
	 
			_sys_user.diminutive = Txtdiminutive.Text.Trim();
 
			_sys_user.sex = Txtsex.Text.Trim();
	 
			_sys_user.collegeid = Txtcollegeid.Text.Trim();
 
			_sys_user.majorid = Txtmajorid.Text.Trim();
		 
			_sys_user.titleid = Txttitleid.Text.Trim();
		 
			_sys_user.rights = Txtrights.Text.Trim();
	 
			_sys_user.telphone = Txttelphone.Text.Trim();
			 
			_sys_user.address = Txtaddress.Text.Trim();
		 
			_sys_user.securityanswer = Txtsecurityanswer.Text.Trim();
	 
			_sys_user.isfreeze = int.Parse(TxtNumisfreeze.Text.Trim());
	 
			_sys_user.workaddress = Txtworkaddress.Text.Trim();
	 
			_sys_user.url = Txturl.Text.Trim();
		 
			_sys_user.emailactivationtime = Txtemailactivationtime.Text.Trim();
			 
			_sys_user.lockkey = int.Parse(TxtNumlockkey.Text.Trim());
	 

            bool isok = false;
            //if (Hid.Text.Length > 0)
            //    isok = mgr.Update_sys_user(_sys_user);
            //else
            ////    isok = mgr.Add_sys_user(_sys_user);
            //if (isok)
            //{
            //    sys_user_Win.Hide();
            //    X.Msg.Notify("成功", "<font color='green'  size='4'>恭喜您，操作成功！</font>").Show();
            //    sys_user_Grid.Reload();
            //}
            //else
            //    X.Msg.Notify("失败", "<font color='red'  size='4'>操作失败，请您重试！</font>").Show();
        }
        //数据保存为Excel
        protected void BtnSaveToExcel(object sender, EventArgs e)
        {
            string json = ExcelGridData.Value.ToString();
            StoreSubmitDataEventArgs eSubmit = new StoreSubmitDataEventArgs(json, null);
            XmlNode xml = eSubmit.Xml;
            this.Response.Clear();
            this.Response.ContentType = "application/vnd.ms-excel";
            this.Response.AddHeader("Content-Disposition", "attachment; filename=QiDian10Excel.xls");
            XslCompiledTransform xtExcel = new XslCompiledTransform();
            xtExcel.Load(Server.MapPath("/View/ExcelTemp/Excel.xsl"));
            xtExcel.Transform(xml, null, this.Response.OutputStream);
            this.Response.End();
        }
    }
}